package com.kitty.record.kittyio.bio.one;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Description
 * @Author SHEN
 * @Date 2021/2/8
 */
public class Server {

    public static void main(String[] args) {

        InputStream inputStream = null;
        BufferedReader bf = null;

        try {
            ServerSocket serverSocket = new ServerSocket(9999);

            Socket accept = serverSocket.accept();

            inputStream = accept.getInputStream();

            bf = new BufferedReader(new InputStreamReader(inputStream));

            String msg = null;

            while ((msg = bf.readLine()) != null){
                System.out.println(msg);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {

            if(inputStream != null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bf != null){
                try {
                    bf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }


    }



}
